//package com.spring.shiro.config;
//
//import com.spring.shiro.entity.User;
//import com.spring.shiro.service.UserService;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.authz.AuthorizationInfo;
//import org.apache.shiro.authz.SimpleAuthorizationInfo;
//import org.apache.shiro.realm.AuthorizingRealm;
//import org.apache.shiro.subject.PrincipalCollection;
//import org.apache.shiro.subject.Subject;
//import org.springframework.beans.factory.annotation.Autowired;
//
//
//public class UserRealm extends AuthorizingRealm {
//
//    @Autowired
//    private UserService userService;
//
//    /**
//     * 执行授权逻辑
//     * @param principalCollection
//     * @return
//     */
//    @Override
//    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
//
//        System.out.println("执行授权逻辑");
//
//        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//
//        //查询当前登陆用户的权限字段串
//        Subject subject = SecurityUtils.getSubject();
//        User principal = (User)subject.getPrincipal();
//
//        //User per = userService.getPer(principal.getId());
//
//        //添加授权资源字符串
//        //info.addStringPermission(per.getPerms());
//
//        return info;
//    }
//
//    /**
//     *执行认证逻辑,执行Login的时候执行
//     * @param authenticationToken
//     * @return
//     * @throws AuthenticationException
//     */
//    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
//
//        UsernamePasswordToken upt = (UsernamePasswordToken)authenticationToken;
//        //User user = userService.getUser(upt.getUsername());
//
////        if(null == user){
////            //用户不存在  返回Null shiro会抛出Un的异常
////            return null;
////        }
//
//        //判断密码  第一个参数会传到上面的授权方法使用
//        return new SimpleAuthenticationInfo("","",getName());
//    }
//}
